import java.math.BigDecimal;

/**
 *
 * @author Jun
 * @date 2019/3/23
 */

public class Account {
    /**
     * 账户号
     */
    private String accountNo;
    /**
     * 账户余额
     */
    private BigDecimal money;

    /**
     * 借贷方向
     */
    private Byte direction;

    /**
     * 增加余额
     * @param value
     * @return
     */
    public synchronized boolean addMoney(BigDecimal value){
        this.money = this.money.add(value);
        return true;
    }

    /**
     * 减少余额
     * @param value
     * @return
     */
    public synchronized boolean subMoeny(BigDecimal value){
        if (this.money.compareTo(value) < 0){
            return false;
        }
        this.money = this.money.subtract(value);
        return true;
    }

    public Account(String accountNo, BigDecimal money, Byte direction) {
        this.accountNo = accountNo;
        this.money = money;
        this.direction = direction;
    }

    public String getAccountNo() {
        return accountNo;
    }

    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    public BigDecimal getMoney() {
        return money;
    }

    public void setMoney(BigDecimal money) {
        this.money = money;
    }

    public Byte getDirection() {
        return direction;
    }

    public void setDirection(Byte direction) {
        this.direction = direction;
    }
}
